package com.lemon.blog.system.controller;

import com.lemon.blog.system.domain.BlType;
import com.lemon.blog.system.service.IBlTypeService;
import com.lemon.common.core.utils.poi.ExcelUtil;
import com.lemon.common.core.web.controller.BaseController;
import com.lemon.common.core.web.domain.AjaxResult;
import com.lemon.common.log.annotation.Log;
import com.lemon.common.log.enums.BusinessType;
import com.lemon.common.security.annotation.RequiresPermissions;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 包名称：com.lemon.blog.controller
 * 类名称：BlTypeController
 * 类描述：分类管理Controller
 * 创建人：@author huangpeng
 * 创建时间：2022-05-04
 */
@Api("博客分类")
@RestController
@RequestMapping("/type")
public class BlTypeController extends BaseController
{
    @Autowired
    private IBlTypeService blTypeService;

    /**
     * 查询分类管理列表
     * @Title: list
     * @Description: 查询分类管理列表
     * @param blType
     * @return: AjaxResult
     * @throws:
     * @author: huangpeng
     * @Date: 2023/2/26 21:38
     */
    @RequiresPermissions("blog:type:list")
    @GetMapping("/list")
    public AjaxResult list(BlType blType) {
        List<BlType> list = blTypeService.selectBlTypeList(blType);
        return AjaxResult.success(list);
    }

    /**
     * 导出分类管理列表
     * @Title: export
     * @Description: 导出分类管理列表
     * @param response
     * @param blType
     * @return: void
     * @throws:
     * @author: huangpeng
     * @Date: 2023/2/26 21:38
     */
    @RequiresPermissions("blog:type:export")
    @Log(title = "分类管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BlType blType) {
        List<BlType> list = blTypeService.selectBlTypeList(blType);
        ExcelUtil<BlType> util = new ExcelUtil<BlType>(BlType.class);
        util.exportExcel(response, list, "分类管理数据");
    }

    /**
     * 获取分类管理详细信息
     * @Title: getInfo
     * @Description: 获取分类管理详细信息
     * @param typeId
     * @return: AjaxResult
     * @throws:
     * @author: huangpeng
     * @Date: 2023/2/26 21:38
     */
    @RequiresPermissions("blog:type:query")
    @GetMapping(value = "/{typeId}")
    public AjaxResult getInfo(@PathVariable("typeId") Long typeId) {
        return AjaxResult.success(blTypeService.selectByPrimaryKey(typeId));
    }

    /**
     * 新增分类管理
     * @Title: add
     * @Description: 新增分类管理
     * @param blType
     * @return: AjaxResult
     * @throws:
     * @author: huangpeng
     * @Date: 2023/2/26 21:38
     */
    @RequiresPermissions("blog:type:add")
    @Log(title = "分类管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BlType blType) {
        return toAjax(blTypeService.insert(blType));
    }

    /**
     * 修改分类管理
     * @Title: edit
     * @Description: 修改分类管理
     * @param blType
     * @return: AjaxResult
     * @throws:
     * @author: huangpeng
     * @Date: 2023/2/26 21:39
     */
    @RequiresPermissions("blog:type:edit")
    @Log(title = "分类管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BlType blType) {
        return toAjax(blTypeService.update(blType));
    }

    /**
     * 删除分类管理
     * @Title: remove
     * @Description: 删除分类管理
     * @param typeIds
     * @return: AjaxResult
     * @throws:
     * @author: huangpeng
     * @Date: 2023/2/26 21:39
     */
    @RequiresPermissions("blog:type:remove")
    @Log(title = "分类管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{typeIds}")
    public AjaxResult remove(@PathVariable Long[] typeIds) {
        return toAjax(blTypeService.deleteByBatch(typeIds));
    }

    /**
     * 查询所有分类
     * @Title: listAll
     * @Description: 查询所有分类
     * @param blType
     * @return: AjaxResult
     * @throws:
     * @author: huangpeng
     * @Date: 2022/5/1 20:28
     */
    @GetMapping("/listAll")
    public AjaxResult listAll(BlType blType) {
        List<BlType> list = blTypeService.selectAll(blType);
        return AjaxResult.success(list);
    }
}
